package Queue;

public class MyArrayQueue {

    //初识化操作
    int[] arr;
    int size = 0;
    //自定义大小
    public MyArrayQueue(int size) {
        arr = new int[size];
    }

    //默认大小
    public MyArrayQueue() {
        arr = new int[10];
    }

    //判断是否队列是否满
    private boolean isFull(){
        return size == arr.length;
    }

    //判断是否队列为空
    private boolean isEmpty(){
        return size == 0;
    }

    //入队列
    public void enQueue(int data){
        if(isFull()){
            System.out.println("入队列操作失败");
            return;
        }
        arr[size] = data;
        size++;
        System.out.println("入队列操作成功");
    }

    //出队列操作
    public int deQueue(){
        if (isEmpty()){
            System.out.println("出队列操作失败");
            return -1;
        }
        int ret = arr[0];
        //接着将后一位把前一位进行覆盖
        for (int i = 1; i < size; i++) {
            arr[i-1] = arr[i];
        }
        size--;
        System.out.println("出队列操作成功");
        return ret;
    }

    //查看队头元素
    public int peek(){
        if (isEmpty()){
            System.out.println("查看队头元素失败");
            return -1;
        }

        return arr[0];
    }

    //打印队列元素
    public void printAll(){
        for (int i = 0; i < size; i++) {
            System.out.print(arr[i] + " ");
        }
    }

}
